﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using Top.Api.Domain;
using System.ComponentModel.DataAnnotations;
using System.Data.Objects;
using System.Data.Common;
using System.Data.Entity.Infrastructure;

namespace TopLibrary
{
    public class TopContext : DbContext
    {
        protected TopContext()
        {
            
        }
        protected TopContext(System.Data.Entity.Infrastructure.DbCompiledModel model)
            : base(model)
        {
            
        }
        public TopContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            
        }
        public TopContext(string nameOrConnectionString, System.Data.Entity.Infrastructure.DbCompiledModel model)
            : base(nameOrConnectionString, model)
        {
            
        }
        public TopContext(System.Data.Common.DbConnection existingConnection, bool contextOwnsConnection)
            : base(existingConnection, contextOwnsConnection)
        {
            
        }
        public TopContext(System.Data.Common.DbConnection existingConnection, System.Data.Entity.Infrastructure.DbCompiledModel model, bool contextOwnsConnection)
            : base(existingConnection, model, contextOwnsConnection)
        {
            
        }
        public TopContext(System.Data.Objects.ObjectContext objectContext, bool dbContextOwnsObjectContext)
            : base(objectContext, dbContextOwnsObjectContext)
        {
            
        }

        public IDbSet<Item> Items { get; set; }
        public IDbSet<Trade> Trades { get; set; }
        public IDbSet<User> Users { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Item>().HasKey(e => e.NumIid);
            modelBuilder.Entity<Item>().Property(e => e.NumIid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.Entity<Trade>().HasKey(e => e.Tid);
            modelBuilder.Entity<Trade>().Property(e => e.Tid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.Entity<Order>().HasKey(e => e.Oid);
            modelBuilder.Entity<Order>().Property(e => e.Oid).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            modelBuilder.ComplexType<Location>();

            base.OnModelCreating(modelBuilder);
        }
    }
}
